"""Definition of the ContentSharingArea content type
"""

from zope.interface import implements, directlyProvides

from Products.Archetypes import atapi
from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata
from Products.CMFPlone.utils import getToolByName


from utpocf.communityofpractice import communityofpracticeMessageFactory as _
from utpocf.communityofpractice.interfaces import IContentSharingArea
from utpocf.communityofpractice.config import PROJECTNAME

ContentSharingAreaSchema = folder.ATFolderSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

))

# Set storage on fields copied from ATFolderSchema, making sure
# they work well with the python bridge properties.

ContentSharingAreaSchema['title'].storage = atapi.AnnotationStorage()
ContentSharingAreaSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(ContentSharingAreaSchema, folderish=True, moveDiscussion=False)

class ContentSharingArea(folder.ATFolder):
    """Container for content sharing services for CoP"""
    implements(IContentSharingArea)

    portal_type = "ContentSharingArea"
    schema = ContentSharingAreaSchema

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    def getRecent(self,limit=5):
        catalog = getToolByName(self,'portal_catalog')
        path = '/'.join(self.getPhysicalPath())
        results = catalog(path=path,
                          sort_on='Date',
                          sort_order='descending',
                          sort_limit=limit)[:limit]

        return results


atapi.registerType(ContentSharingArea, PROJECTNAME)
